Skip to content

Implement scantxoutset method and test #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GideonBature
Copy link
Contributor

@GideonBature GideonBature commented May 12, 2025

The JSON-RPC method scantxoutset does return a type. We want to test this to catch any changes in behavior in future Core versions.

This PR adds a client function that errors if the return value is anything other than the type it returns, along with an integration test that calls this function.

Ref: #116
Closes #115

@GideonBature GideonBature force-pushed the scantxoutset branch 3 times, most recently from 63e4f61 to 67b03b6 Compare May 12, 2025 23:49
@tcharding
Copy link
Member

Why is there identical code in the v17 and v18 blockchain modules of the client?

@GideonBature
Copy link
Contributor Author

Why is there identical code in the v17 and v18 blockchain modules of the client?

They basically work the same way, the difference is in their return type, v18 has an additional field (desc) in it's result, whereas it is lacking in v17. Or is there a way to reuse the client code in v17 for v18 and still be able to return the type that is meant for v18?

@tcharding
Copy link
Member

Bro I explained this to you already on the other two PRs you did. Perhaps go back over them and see if you can work it out.

@GideonBature
Copy link
Contributor Author

GideonBature commented May 14, 2025

Bro I explained this to you already on the other two PRs you did. Perhaps go back over them and see if you can work it out.

oh, I now understand, I was looking at how gettxout was used in the client, where despite the code is similar, they used it for v17 and again for v22. So I thought that for any change in the fields of return type of a method, there should also be a code in the module of the client for that particular version with the change. But I can see that it's not always the case.

For this recent push, I removed the repeated code across all versions having different fields in their type.

@tcharding
Copy link
Member

Oh well that would explain your confusion, the gettxout in v22 is just plain wrong. I'll remove it.

@tcharding
Copy link
Member

Done in #169. FTR bugs happen, if you see things that are wrong or look weird just ask (or PR to fix them). Apologies for being so fierce yesterday.

@tcharding
Copy link
Member

tcharding commented May 15, 2025

Returns column needs updating (and Notes).

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holy moly you picked a difficult one. I'm going to have to come back to this when I can put more thought into it. Feel free to ignore my suggestions until then.

@GideonBature
Copy link
Contributor Author

Done in #169. FTR bugs happen, if you see things that are wrong or look weird just ask (or PR to fix them). Apologies for being so fierce yesterday.

No problem. I will do this going forward.

@GideonBature
Copy link
Contributor Author

Returns column needs updating (and Notes).

Noted!

@GideonBature
Copy link
Contributor Author

Holy moly you picked a difficult one. I'm going to have to come back to this when I can put more thought into it. Feel free to ignore my suggestions until then.

Noted....

@GideonBature
Copy link
Contributor Author

Returns column needs updating (and Notes).

for the notes, is there any need to change it? since it describes perfectly that the scantxoutset is experimental.

@tcharding
Copy link
Member

Oh you are right, lets leave the notes as they are.

@tcharding
Copy link
Member

Man this method is really not that simple to add support for because it changes so often. Can we put this one on hold until you've got a few more easy ones done?

@tcharding tcharding marked this pull request as draft May 27, 2025 05:41
@GideonBature
Copy link
Contributor Author

Man this method is really not that simple to add support for because it changes so often. Can we put this one on hold until you've got a few more easy ones done?

Understood... sure, let's do that.

@GideonBature GideonBature deleted the scantxoutset branch May 31, 2025 08:09
@GideonBature GideonBature restored the scantxoutset branch May 31, 2025 08:35
@GideonBature GideonBature reopened this May 31, 2025
@GideonBature GideonBature marked this pull request as ready for review July 15, 2025 14:42
@GideonBature
Copy link
Contributor Author

Complete the scantxoutset method and model.

@GideonBature GideonBature requested a review from tcharding July 15, 2025 14:50
}

#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct ScanTxOutSetStatus {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation: This struct never changes

Use git grep -A 4 'pub struct ScanTxOutSetStatus' to see.

}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct ScanTxOutSetStart {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. Perhaps add #[serde(deny_unknown_fields)] to all your structs and that will help find the bugs.

Copy link
Collaborator

@jamillambert jamillambert Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added #[serde(deny_unknown_fields)] to this to test, and there are two missing fields, success and searched_items.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've done a bunch of work, well done. This one is pretty curly, here are some ideas.

I think it would be more simple if we were to split up the return types for the three different commands (start, abort, status). That way we only have to re-implement the ones that change.

In the client I think it would be more simple to have three methods, one for each command and not have a ScanAction type.

Instead of ScanObject I think we can just use a String and ignore the added complexity of an object (the WithDesc variant) since it is unused. In general we don't want to add code to the client that we do not use in testing.

That should give you a bit to work on!

Copy link
Collaborator

@jamillambert jamillambert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some missing renames, relates to issue #298. I haven't necessarily highlighted all of them.

@GideonBature
Copy link
Contributor Author

You've done a bunch of work, well done. This one is pretty curly, here are some ideas.

I think it would be more simple if we were to split up the return types for the three different commands (start, abort, status). That way we only have to re-implement the ones that change.

In the client I think it would be more simple to have three methods, one for each command and not have a ScanAction type.

Instead of ScanObject I think we can just use a String and ignore the added complexity of an object (the WithDesc variant) since it is unused. In general we don't want to add code to the client that we do not use in testing.

That should give you a bit to work on!

This suggestion is much better. Will work with it. Thank you.

Split single return type to three types

Rename some fields for readability

Rename some fields for readability
@GideonBature
Copy link
Contributor Author

Implemented suggested changes.

Format code
Copy link
Collaborator

@jamillambert jamillambert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few comments, they apply to all affected versions.

@@ -19,7 +19,8 @@ use crate::types::v29::*;

#[rustfmt::skip] // Keep public re-exports separate.
pub use crate::client_sync::{
v17::{AddNodeCommand, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp, Input, Output, SetBanCommand, WalletCreateFundedPsbtInput,},
v17::{AddNodeCommand, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp, Input, Output, SetBanCommand, WalletCreateFundedPsbtInput
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This change is unrelated and wrong. It's not fixed by cargo fmt due to the skip above the block.

NB. I'm ok with the random fix being in this PR if done correctly though.

Comment on lines +696 to +698

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct ScanTxOutSetAbort(pub bool);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rustdocs

Comment on lines +700 to +704
#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct ScanTxOutSetStatus {
/// Approximate percent complete
pub progress: f64,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct ScanTxOutSetStatus {
/// Approximate percent complete
pub progress: f64,
}
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct ScanTxOutSetStatus(pub f64);

Also needs docs. Was there a reason serialize was not included that I have missed?


let _: Option<ScanTxOutSetStatus> = node.client.scan_tx_out_set_status().expect("scantxoutset status");

let model: Result<mtype::ScanTxOutSetStart, ScanTxOutSetError> = json.into_model();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this line to directly below let json makes more sense. I had to look twice and first thought the model for ..Status was being checked and not ..Start.

pub total_amount: Amount,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
Copy link
Collaborator

@jamillambert jamillambert Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
/// Unspents item returned as part of `scantxoutset`
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

Needs docs, e.g. above. Having scanned through the code a lot recently I find it useful if the original RPC is mentioned.

}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct ScanTxOutSetStart {
Copy link
Collaborator

@jamillambert jamillambert Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added #[serde(deny_unknown_fields)] to this to test, and there are two missing fields, success and searched_items.

/// > Returns an object containing various state info regarding blockchain processing.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct GetBlockchainInfo {
Copy link
Collaborator

@jamillambert jamillambert Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the changes to this file are not part of this PR, left over from a copy and paste from v19?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement version specific types for status 'omitted' methods
3 participants